import Vue from 'vue'
import Router from 'vue-router'

import departmentRouter from './modules/department'
import roleRouter from './modules/role'
import employeeRouter from './modules/employee'
import permissionRouter from './modules/permission'
import approvalRouter from './modules/approval'
import attendanceRouter from './modules/attendance'
import salaryRouter from './modules/salary'
import socialRouter from './modules/social'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  // 登录
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  // 404页面
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  // 首页
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '首页', icon: 'dashboard' }
      }
    ]
  },
  // 组织
  departmentRouter,
  // 角色
  roleRouter,
  // 员工
  employeeRouter,
  // 权限
  permissionRouter,
  // 审批
  approvalRouter,
  // 考勤
  attendanceRouter,
  // 工资
  salaryRouter,
  // 社保
  socialRouter,

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

// 创建路由对象
const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}
// 默认导出路由
export default router
